<?php	
$json = json_decode(file_get_contents('php://input'), true);
if(!$json)
	$json = array();
$host = "192.168.30.17";
$user = "emomap";
$pass = "Salome";
$db = "topoemotion";
	
$con = pg_connect("host=$host dbname=$db user=$user password=$pass")
    or die ("Could not connect to server\n");
	
$query = "SELECT insert_te($1,$2,$3,$4,$5,$6);";
pg_prepare($con, "prepare1", $query)
    or die ("Cannot prepare statement\n");
	
foreach ($json as $value) {
        $textsid = sprintf("%.0f", $value["sid"]);
        $bliked = $value["liked"] ? "true" : "false"; 
	$rs = pg_execute($con, "prepare1", array($textsid, 
	                                         $value["category"],
	                                         $bliked,
	                                         $value["latitude"],
	                                         $value["longitude"],
	                                         $value["accuracy"]))
    		or die ("Cannot execute statement\n");
	}
?>
